package service

import (
	"RocFamilySystem/internal/repository"
	"RocFamilySystem/models"
)

type SysMenuService struct {
	SysMenuRepository *repository.SysMenuRepository
}

// 初始化
func init() {
	registerContainer["SysMenuService"] = &SysMenuService{}
}

// SetRepository 设置持久层
func (service *SysMenuService) SetRepository(sysMenuRepository *repository.SysMenuRepository) {
	service.SysMenuRepository = sysMenuRepository
}

// AddSysMenu 添加系统菜单
func (service *SysMenuService) AddSysMenu(sysMenu *models.SysMenu) {
	service.SysMenuRepository.InsertSysMenu(sysMenu)
}

// RemoveSysMenu 删除系统菜单
func (service *SysMenuService) RemoveSysMenu(sysMenuId int) {
	service.SysMenuRepository.DeleteSysMenu(sysMenuId)
}

// RemoveSysMenuBatch 批量删除系统菜单
func (service *SysMenuService) RemoveSysMenuBatch(ids []string) {
	service.SysMenuRepository.DeleteSysMenuBatch(ids)
}

// ModifySysMenu 修改系统菜单
func (service *SysMenuService) ModifySysMenu(sysMenu *models.SysMenu) {
	service.SysMenuRepository.UpdateSysMenu(sysMenu)
}

// QuerySysMenu 查询系统菜单
func (service *SysMenuService) QuerySysMenu(sysMenu *models.SysMenu, pageNum, pageSize int) PageInfo {
	tables, total := service.SysMenuRepository.SelectSysMenu(sysMenu, pageNum, pageSize)
	return toPageInfo(pageNum, pageSize, total, tables)
}

// QuerySysMenuById 通过ID查询系统菜单
func (service *SysMenuService) QuerySysMenuById(id int) models.SysMenu {
	return service.SysMenuRepository.SelectSysMenuById(id)
}
